<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=no" name="format-detection" />
<meta content="email=no" name="format-detection" />
<title></title>

<link rel="stylesheet" href="../../css/s_plus.css" />
<link rel="stylesheet" href="../../css/base.css" />
<link rel="stylesheet" href="../../css/layout.css" />
<link rel="stylesheet" href="../../css/choice.css" />
<script type="text/javascript" src="../../libs/vue.js" ></script>
<script type="text/javascript" src="../../js/jquery.1.9.1.min.js" ></script>
<script type="text/javascript" src="../../js/app/url.js" ></script>
<script type="text/javascript" src="../../libs/hui.js" ></script>
<script type="text/javascript" src="../../js/app/api.js"></script>
<script type="text/javascript" src="../../js/md5.js"></script>



</head>
<body>
	<div id="app">

<header class="f_l maxbox subhead">
  <a class="back" @click="back"><i class="iconfont">&#xe605;</i></a>
  <h1>找回密码</h1>
</header>
<section class="f_l maxbox password_list">
  <dl>
    <dt>请输入您的用户名</dt>
    <dd><input class="password_txt" v-model="username" type="text" placeholder="请输入用户名"></dd>
    <dd><input class="password_txt" v-model="code" type="text" placeholder="请输入验证码"><a class="code" @click="sendCode"  :disabled="disable_code">{{btn_msg}}</a></dd>
  </dl>
  <dl>
    <dt>请输入新的密码进行设置。</dt>
    <dd><input class="password_txt" name="" v-model="password1" type="password" placeholder="请输入新密码"></dd>
    <dd><input class="password_txt" name=""  v-model="password2" type="password" placeholder="再次输入新密码"></dd>
  </dl>
</section>
<section class="t_c red" v-text="info">错误提示</section>
<section class="f_l maxbox mar_t mar_f t_c">
  <a class="btn mian_btn" @click="submitData">下一步</a>
</section>

		
		
	</div>
<script>
	
		var vm = new Vue({
				el:"#app",
				data:{
					username:"",
					code:"",
					password1:"",
					password2:"",
					disable_code:"",
					btn_msg:'获取验证码',
					info:""
				},
				
				methods:{
					back:function(){
//						window.history.back(-1);
						hui.back();
					},
					
						sendCode : function(){
						//this.showAll();
							if(vm.disable_code){
								return;
							}

						
						if(isEmpty(this.username)){
							 this.info='请输入用户名';
							 hui.toast('请输入用户名', 2);

							  return;
						}
						

							var path =  urlManager.sendCode()+"?loginName="+this.username;
							console.log(path);

							time();
//							return;

							$.ajax({
								type: "GET",
								url: path,
									beforeSend: function(request) {
									},
									success: function(result) {
										if(result&&result.result=='0'){
											hui.toast('验证码发送成功',2);
										}
										else{
//											hui.toast('发送失败',2);
										}
									}
								});
						
					
						},
						
					  submitData:function(){
					  		if(isEmpty(this.code)){
							 this.info='请输入验证码';
							 hui.toast('请输入验证码', 2);
							  return;
						}
					  	
					  	if(isEmpty(this.password1)){
					  		vm.info="请输入新密码";
					  		hui.toast('请输入新密码', 2);
					  		return;
					  	}
					  	if(isEmpty(this.password2)){
					  		vm.info="请再次输入密码";
					  		hui.toast('请再次输入密码', 2);
					  		return;
					  	}
					  		
					  	if(this.password2!=this.password1){
					  		vm.info="两次输入密码不一致，请重新输入";
					  		hui.toast('两次输入密码不一致，请重新输入', 2);
					  		return;
					  	}
					  	
					
					  	if(isEmpty(this.code)){
					  		vm.info="验证码不能为空";
					  		hui.toast('验证码不能为空', 2);

					  		return;
					  	}
					  	var path =  urlManager.resetPwd()+"?loginName="+this.username+"&code="+this.code+"&passWord="+this.password2;
							console.log(path);


							$.ajax({
								type: "GET",
								url: path,
									beforeSend: function(request) {
//										request.setRequestHeader("loginName", "Chenxizhang");
//										request.setRequestHeader("passWord", "******");
				
									},
									success: function(result) {

										console.log(JSON.stringify(result));
										if(result.result=="0"){
											hui.toast(JSON.stringify(result.message),3);

											vm.info="";
											hui.open("../../login.html", {}, true, {});
										}
										else{
									hui.toast(JSON.stringify(result.message));

										}
										//alert(result);
									}
								});
					
					}
					}
				,
				mounted: function() {
							var username=	localStorage.getItem("paramUsername");
							this.username=username;
			}
				
				});
				
					//判断字符是否为空的方法
					function isEmpty(obj){
					    if(typeof obj == "undefined" || obj == null || obj == ""){
					        return true;
					    }else{
					        return false;
					    }
					}
					
					
						var interval=30;//发送验证码时间间隔(s)
					var wait=interval; 
					function time() {  
					        if (wait == 0) {  
					        	vm.disable_code=false;
					           // o.removeAttribute("disabled");            
					            //o.value="免费获取验证码";
					            vm.btn_msg='获取验证码';
					            wait = interval;  
					        } else {  
					        	vm.disable_code=true;

					            //o.setAttribute("disabled", true);  
					           // o.value="(" + wait + "秒)后重新发送"; 
					            vm.btn_msg="(" + wait + "秒)后重发"; 
					            wait--;  
					            setTimeout(function() {  
					                time()  
					            },  
					            1000)  
					        }  
					    }  
	
	
	
</script>
</body>
</html>